﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace USBControlLib.Settings
{
    public class USBConnectSetting
    {
        public int Language { get; set; } = 1;
        public int TimeUSB1ON { get; set; } = 5;
        public int TimeUSB1OFF { get; set; } = 5;
        public int TimeUSB2ON { get; set; } = 5;
        public int TimeUSB2OFF { get; set; } = 5;
        public int TimeUSB3ON { get; set; } = 5;
        public int TimeUSB3OFF { get; set; } = 5;
        public int TimeUSB4ON { get; set; } = 5;
        public int TimeUSB4OFF { get; set; } = 5;
        public int TimeUSB5ON { get; set; } = 5;
        public int TimeUSB5OFF { get; set; } = 5;
        public int TimeUSB6ON { get; set; } = 5;
        public int TimeUSB6OFF { get; set; } = 5;
        public int TimeUSB7ON { get; set; } = 5;
        public int TimeUSB7OFF { get; set; } = 5;
        public int TimeUSB8ON { get; set; } = 5;
        public int TimeUSB8OFF { get; set; } = 5;
        public USBConnectSetting()
        {

        }

        public async Task OnWaiting(int channel, int action)
        {
            List<int> listOn= new List<int>();
            List<int> listOff = new List<int>();
            listOn.Add(this.TimeUSB1ON);
            listOn.Add(this.TimeUSB2ON);
            listOn.Add(this.TimeUSB3ON);
            listOn.Add(this.TimeUSB4ON);
            listOn.Add(this.TimeUSB5ON);
            listOn.Add(this.TimeUSB6ON);
            listOn.Add(this.TimeUSB7ON);
            listOn.Add(this.TimeUSB8ON);

            listOff.Add(this.TimeUSB1OFF);
            listOff.Add(this.TimeUSB2OFF);
            listOff.Add(this.TimeUSB3OFF);
            listOff.Add(this.TimeUSB4OFF);
            listOff.Add(this.TimeUSB5OFF);
            listOff.Add(this.TimeUSB6OFF);
            listOff.Add(this.TimeUSB7OFF);
            listOff.Add(this.TimeUSB8OFF);
            int index = channel - 1;
            switch (action)
            {
                case 1:
                    {
                        int sec = listOn[index];
                        await Task.Delay(1000 * sec);
                        break;
                    }                
                case 2:
                    {
                        int sec = listOff[index];
                        await Task.Delay(1000 * sec);
                        break;
                    }
                case 3:
                    {
                        int sec = listOn[index]+listOff[index];
                        await Task.Delay(1000 * sec);
                        break;
                    }
                default:
                    break;
            }
        }
    }
}
